//package com.aco.party.common.filter;
//
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.HashSet;
//import java.util.List;
//import java.util.Set;
//import java.util.regex.Pattern;
//
//import javax.servlet.Filter;
//import javax.servlet.FilterChain;
//import javax.servlet.FilterConfig;
//import javax.servlet.ServletException;
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.slf4j.Logger;
//
//import com.icss.background.auth.login.constants.AuthConstants;
//import com.icss.background.common.config.ApplicationConfig;
//import com.icss.background.common.log.LoggerManager;
//
///**
// * 对静态文件进行缓存
// * <P>Title: FileCacheFilter</P>
// * <P>Description: create by XSDToJava V1.0</P>
// * <P>Copyright: Copyright (c) 2013 </P>
// * <P>Company: xunzuo </P>
// * 
// * @author lj
// * @version 1.0
// * @create 2013-8-16
// * @history
// */
//public class FileCacheFilter implements Filter {
//	/**
//	 * logger
//	 */
//	private static Logger logger = LoggerManager.getLogger(FileCacheFilter.class);
//	/**
//	 * 缓存时间默认24小时
//	 */
//	private Integer cacheTime = 3600 * 24;
//	private List<Pattern> patternList = new ArrayList<Pattern>();
//	private static Set<String> cacheSet = new HashSet<String>();
//
//	// private static ResourceBundle rb = ResourceBundle.getBundle("fileCacheFilter");
//	@Override
//	public void destroy() {
//	}
//
//	@Override
//	public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException {
//		fc.doFilter(req, res);
//		if (req instanceof HttpServletRequest && res instanceof HttpServletResponse) {
//			HttpServletRequest request = (HttpServletRequest) req;
//			HttpServletResponse response = (HttpServletResponse) res;
//			if (matchPattern(request.getRequestURI())) {
//				if (request.getSession().getAttribute(AuthConstants.LOGIN_STAFF) == null) {
////					refesh();
//				} else {
////					cacheSet.add(request.getRequestURI());
//					response.setHeader("Cache-Control", "max-age=" + cacheTime);
//					if (logger.isDebugEnabled()) {
//						StringBuilder sb = new StringBuilder(128);
//						sb.append(" set cache control for uri = ").append(request.getRequestURI());
//						sb.append(" and the cache time is ").append(cacheTime).append("second");
//						logger.debug(sb.toString());
//					}
//				}
//			}
//		} else {
//			if (logger.isWarnEnabled()) {
//				logger.warn("---- the request instance is not instanceof HttpServletRequest ---");
//				logger.warn("---- the response instance is not instanceof HttpServletResponse ---");
//			}
//		}
//	}
//
//	@Override
//	public void init(FilterConfig arg0) throws ServletException {
//		// Enumeration<String> keys = rb.getKeys();
//		// while (keys.hasMoreElements()) {
//		// String p = keys.nextElement();
//		// String value = rb.getString(p);
//		// patternList.add(Pattern.compile(value, Pattern.CASE_INSENSITIVE));
//		// if (logger.isInfoEnabled()) {
//		// logger.info(">>>>>>>>>>> init the cache pattern " + value);
//		// }
//		// }
//		Set<String> caches = ApplicationConfig.getInstance().getPortalbgCaches();
//		if (caches != null && caches.size() > 0) {
//			for (String value : caches) {
//				patternList.add(Pattern.compile(value, Pattern.CASE_INSENSITIVE));
//				if (logger.isInfoEnabled()) {
//					logger.info(">>>>>>>>>>> init the cache pattern " + value);
//				}
//			}
//		}
//		if (arg0 != null) {
//			String ct = arg0.getInitParameter("cache-time");
//			if (!"".equals(ct) && null != ct) {
//				cacheTime = new Integer(ct);
//				if (logger.isInfoEnabled()) {
//					logger.info(">>>>>>>>>> the cache time is " + cacheTime);
//				}
//			}
//		}
//	}
//
//	private boolean matchPattern(String url) {
//		for (Pattern pattern : patternList) {
//			// if (pattern.matcher(url).matches()) {
//			if (url.contains(pattern.toString())) {
//				return true;
//			}
//		}
//		return false;
//	}
//
//	@SuppressWarnings("unused")
//	private void refesh() {
//		cacheSet.clear();
//	}
//
//	public static void main(String[] args) throws ServletException {
//		FileCacheFilter fcf = new FileCacheFilter();
//		fcf.init(null);
//		System.out.println(fcf.matchPattern("/css/prototype.CSS"));
//	}
//}
